/*** Eclipse Class Decompiler plugin, copyright (c) 2012 Chao Chen (cnfree2000@hotmail.com) ***/
package com.qihoo.gamecenter.sdk.support.cservice;

import android.content.Context;
import android.view.MotionEvent;
import android.view.View;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.Adapter;
import android.widget.ListAdapter;
import android.widget.ListView;
import com.qihoo.gamecenter.sdk.common.i.s;

public final class AutoLoadListView extends ListView implements AbsListView.OnScrollListener {
    private int a = 0;
    private float b = 0.0F;
    private float c = 0.0F;
    private boolean d = true;
    private boolean e = true;
    private boolean f = false;
    private Context g;
    private Runnable h;
    private Runnable i;
    private LoadButton j;
    private LoadButton k;
    private a l;
    private AbsListView.OnScrollListener m;

    public AutoLoadListView(Context paramContext) {
        super(paramContext);
        this.g = paramContext;
        a();
        super.setOnScrollListener(this);
    }

    private void a() {
        this.j = new LoadButton(this.g, true);
        this.j.setOnBtnClickListener(new LoadButton.a() {
            public void a(View paramView, String paramString) {
                if ((!("load_btn_to_load".equals(paramString))) || (AutoLoadListView.a(AutoLoadListView.this) == null))
                    return;
                AutoLoadListView.a(AutoLoadListView.this).d();
            }
        });
        this.j.setPadding(0, s.b(this.g, 10.0F), 0, 0);
        addHeaderView(this.j);
        c();
        this.k = new LoadButton(this.g, true);
        this.k.setPadding(0, 0, 0, s.b(this.g, 10.0F));
        View localView = new View(this.g);
        addFooterView(localView);
    }

    private boolean b() {
        return this.j.c();
    }

    private void c() {
        this.j.b();
    }

    private boolean d() {
        if (getFooterViewsCount() == 1) {
            addFooterView(this.k);
            this.k.c();
            return true;
        }
        return false;
    }

    private void a(boolean paramBoolean) {
        this.k.b();
        removeFooterView(this.k);
    }

    private boolean b(boolean paramBoolean) {
        if ((!(this.e)) && (paramBoolean))
            return true;
        ListAdapter localListAdapter = getAdapter();
        if (localListAdapter == null)
            return false;
        return ((getLastVisiblePosition() - getFirstVisiblePosition() + 1 < localListAdapter.getCount()) && (c(paramBoolean)));
    }

    public boolean onTouchEvent(MotionEvent paramMotionEvent) {
        int i1 = paramMotionEvent.getAction();
        switch (i1) {
        case 0:
            this.b = paramMotionEvent.getY();
            this.f = (getFirstVisiblePosition() < 1);
            break;
        case 2:
            this.c += paramMotionEvent.getY() - this.b;
            break;
        case 1:
        case 3:
            this.c = 0.0F;
        }
        return super.onTouchEvent(paramMotionEvent);
    }

    private boolean c(boolean paramBoolean) {
        return (((this.e ^ paramBoolean)) ? true : this.d);
    }

    public void setIsInversion(boolean paramBoolean) {
        this.e = paramBoolean;
    }

    public void setAnyEarlierMore(boolean paramBoolean) {
        this.d = paramBoolean;
        this.j.a();
    }

    public void a(boolean paramBoolean1, boolean paramBoolean2) {
        if ((this.e ^ paramBoolean1))
            a(paramBoolean2);
        else
            c();
    }

    public void setOnLoadListener(a parama) {
        this.l = parama;
    }

    public void setAdapter(ListAdapter paramListAdapter) {
        super.setAdapter(paramListAdapter);
    }

    public final void setOnScrollListener(AbsListView.OnScrollListener paramOnScrollListener) {
        this.m = paramOnScrollListener;
    }

    public final void onScrollStateChanged(AbsListView paramAbsListView, int paramInt) {
        this.a = paramInt;
        if (this.a == 0) {
            if ((getLastVisiblePosition() >= getCount() - 1) && (this.h != null))
                postDelayed(this.h, 1000L);
            else
                a(false);
            if ((getFirstVisiblePosition() < 1) && (this.i != null) && (this.f))
                postDelayed(this.i, 1000L);
            else
                c();
            this.h = null;
            this.i = null;
        }
        else {
            if ((getLastVisiblePosition() == getCount() - 1) && (b(false)) && (this.c < 0.0F) && (d()))
                this.h = new Runnable() {
                    public void run() {
                        if (AutoLoadListView.a(AutoLoadListView.this) == null)
                            return;
                        if (AutoLoadListView.b(AutoLoadListView.this))
                            AutoLoadListView.a(AutoLoadListView.this).e();
                        else
                            AutoLoadListView.a(AutoLoadListView.this).d();
                    }
                };
            if ((getFirstVisiblePosition() < 1) && (b(true)) && (this.c > 0.0F) && (this.f) && (b()))
                this.i = new Runnable() {
                    public void run() {
                        if (AutoLoadListView.a(AutoLoadListView.this) == null)
                            return;
                        if (AutoLoadListView.b(AutoLoadListView.this))
                            AutoLoadListView.a(AutoLoadListView.this).d();
                        else
                            AutoLoadListView.a(AutoLoadListView.this).e();
                    }
                };
        }
        if (this.m == null)
            return;
        this.m.onScrollStateChanged(paramAbsListView, paramInt);
    }

    public final void onScroll(AbsListView paramAbsListView, int paramInt1, int paramInt2, int paramInt3) {
        if (this.m == null)
            return;
        this.m.onScroll(paramAbsListView, paramInt1, paramInt2, paramInt3);
    }

    public static abstract interface a {
        public abstract void d();

        public abstract void e();
    }
}